package org.wu.framework.inner.lazy.orm.spring;

import org.springframework.jdbc.datasource.DataSourceUtils;
import org.wu.framework.lazy.database.datasource.proxy.handler.AbstractConnectionHandler;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class SpringConnectionHandler extends AbstractConnectionHandler {
    /**
     * 获取事物状态
     *
     * @param dataSource 数据源
     * @param connection 数据源中的连接
     */
    @Override
    public boolean isConnectionTransactional(DataSource dataSource, Connection connection) {
        return DataSourceUtils.isConnectionTransactional(connection, dataSource);
    }

    /**
     * 释放连接
     *
     * @param dataSource 数据源
     * @param connection 数据源中的连接
     */
    @Override
    public void connectionClose(DataSource dataSource, Connection connection) throws SQLException {
        DataSourceUtils.releaseConnection(connection, dataSource);
        // 事务失效
//        connection.connectionClose();
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
